package ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.completeRFCPanel.completeRFCSubs.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.model.RFC;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.completeRFCPanel.completeRFCSubs.ChooseCompleteRFCDialog;

public class LoadOpenRFCDialogButtonListener extends MouseAdapter implements
		ActionListener {

	private ChooseCompleteRFCDialog chooseCompleteRFCDialog;

	public LoadOpenRFCDialogButtonListener(
			ChooseCompleteRFCDialog chooseCompleteRFCDialog) {
		this.chooseCompleteRFCDialog = chooseCompleteRFCDialog;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {

		RFC rfc = chooseCompleteRFCDialog.getDisplayTable()
				.getSelectedRFCinTable();
		if (rfc != null) {
			this.loadopenRFC(rfc);
		}
	}

	@Override
	public void mouseClicked(MouseEvent arg0) {

		if (arg0.getClickCount() == 2) {
			RFC rfc = chooseCompleteRFCDialog.getDisplayTable()
					.getSelectedRFCinTable();
			if (rfc != null) {

				this.loadopenRFC(rfc);

			}
		}
	}

	private void loadopenRFC(RFC rfc) {
		
		
		this.chooseCompleteRFCDialog.getCompleteRFCPanel().getListPanel().setup(rfc);
		this.chooseCompleteRFCDialog.getCompleteRFCPanel().getFunctionPanel().getLoadUncompleteRFCButton().setEnabled(false);
		this.chooseCompleteRFCDialog.getCompleteRFCPanel().getFunctionPanel().getReadyforapprovalButton().setEnabled(true);
		this.chooseCompleteRFCDialog.getCompleteRFCPanel().getFunctionPanel().getCancelButton().setEnabled(true);
		this.chooseCompleteRFCDialog.dispose();
	}
}
